package com.jprocms.module.cms.util;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;

import java.util.Date;

/**
 * @author jprocms
 * 用于 date转cron
 */
public class CronUtil {

    /**
     * 每月时间format格式
     */
    public static final String CRON_DATE = "ss mm HH dd MM ? yyyy";
    /**
     * 每月时间format格式
     */
    public static final String CRON_MONTH = "ss mm HH dd * ?";

    /**
     * 每天时间format格式
     */
    public static final String CRONT_EVERYDAY = "ss mm HH * * ?";

    /**
     * 每周时间format格式
     */
    public static final String SUNDAY = "ss mm HH ? * 1";
    public static final String MONDAY = "ss mm HH ? * 2";
    public static final String TUESDAY = "ss mm HH ? * 3";
    public static final String WEDNESDAY = "ss mm HH ? * 4";
    public static final String THURSDAY = "ss mm HH ? * 5";
    public static final String FRIDAY = "ss mm HH ? * 6";
    public static final String SATURADY = "ss mm HH ? * 7";

    public static String date2Cron(Date date, String dateFormat) {
        Assert.notNull(date, "date must not null");
        Assert.notNull(dateFormat, "dateFormat must not null");
        String cron = null;
        if (date != null) {
            cron = DateUtil.format(date, dateFormat);
        }
        return cron;
    }

}
